// pages/mine/babyClass/qingjia/qingjia
const $api = require("../../../../api/mine").API

Page({

  /**
   * 页面的初始数据
   */
  data: {
    false:false,
    true:true,
    show:false,
    showstart:false,
    columns: [
      {
        key:1,
        value:"事假"
      }
    ],
    currentDate: new Date().getTime(),
    minDate: new Date().getTime(),
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      } else if (type === 'month') {
        return `${value}月`;
      }
      return value;
    },
    time:"选择截止时间",
    taskType:"固定任务",
    endtime:"",
    starttime:"",
    timekey:0,
    showtype:false,
    item_type_name:"",
    item_type:"",
    leave_count:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  settime(e){
    var t = this
    t.setData({
      showstart:true,
      timekey:e.currentTarget.dataset.key
    })
  },
  closetime(e){
    var t = this
    t.setData({
      showstart:false
    })
  },
  onInput(event) {
    this.setData({
      currentDate: event.detail,
    });
  },
  afterRead(e){
    var t =this
    console.log(33333)
    wx.chooseImage({
      count: 1,	// 默认为9
      sizeType: ['original', 'compressed'],	// 指定原图或者压缩图
      sourceType: ['album', 'camera'],	// 指定图片来源
      success: function(res) {
        var tempFilePaths = [{
          url:res.tempFilePaths[0],
          name:'图片'
        }]
        t.setData({
          fileList:tempFilePaths
        })
        console.log(tempFilePaths)
      }
    })
  },
  onInputstart(e){
    var t = this
    var starttime = t.timeformat(e.detail)
    if(t.data.timekey==1){
      t.setData({
        starttimeinfo:starttime
      })
    }else if(t.data.timekey==2){
      t.setData({
        endtimeinfo:starttime
      })
    }else{
      t.setData({
        starttimeinfo:starttime,
        endtimeinfo:starttime
      })
    }
    
  },
  timeformat(times){
    var t= this
    var mydate = new Date(parseInt(times))
    var y = mydate.getFullYear(),
        m = t.zeroFill(mydate.getMonth()+1),
        d = t.zeroFill(mydate.getDate()),
        h = t.zeroFill(mydate.getHours()),
        i = t.zeroFill(mydate.getMinutes()),
        s = t.zeroFill(mydate.getSeconds())
    return  [y,m,d].join("-") + " " + [h,i,s].join(":")
  },
  zeroFill(str, n=2){
    //补零方法，str为数字字符串 n为需要的位数，不够补零
    if ( str.toString().length < n){
     str = '0'+str.toString()
    }
    return str
   },
   closetype(){
     var t = this
     t.setData({
      showtype:false
      
     })
   },
   settype(){
     var t= this
     t.setData({
      showtype:true
     })
   },
   onChangetype(e){
     var t= this
     console.log(e)
     t.setData({
      item_type:e.detail.value.key,
      item_type_name:e.detail.value.value
     })
     t.closetype()
   },
   setleave_count(e){
     var t = this
     t.setData({
      leave_count:e.detail
     })
   },
<<<<<<< HEAD
   // 请假提交
   saveLeaveRecord(){
     var t = this,
     data = {
      child_id:wx.getStorageSync('child_one').child_id,
=======
   // 联系老师
   saveLeaveRecord(){
     var t = this,
     data = {
      child_id:wx.getStorageSync('childinfo').child_id,
>>>>>>> 1c9ce1fdc7fcbf1a028b999eb3cd07f698a8a329
      item_id:wx.getStorageSync('user').member_id,
      item_type:t.data.item_type,
      start_time:t.data.starttimeinfo,
      end_time:t.data.endtimeinfo
     }
     $api.saveLeaveRecord(data).then(res=>{
<<<<<<< HEAD
       console.log(res.status)
       if(res.status==200){
        wx.showToast({
          title: '成功',
          icon: 'success',
          duration: 2000,
          success:function(){
            setTimeout(function () {
              //要延时执行的代码
              wx.redirectTo({
                url: '/pages/mine/babyClass/babyClass',
              })
            }, 2000) //延迟时间
          }
        })
       }
=======
       console.log(res)
>>>>>>> 1c9ce1fdc7fcbf1a028b999eb3cd07f698a8a329
     })
   }
})